<?php

namespace App\Controller\Admin;

use App\Controller\ApiController;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Logger\LoggerFactory;
use Psr\Http\Message\ResponseInterface;
use Throwable;

class MenusController extends ApiController
{
    #[Inject]
    protected \App\Logic\Admin\MenusLogic $menusLogic;
    public function __construct(LoggerFactory $loggerFactory)
    {
        parent::__construct($loggerFactory);
        $this->menusLogic = new \App\Logic\Admin\MenusLogic();
    }

    /**
     * Notes:获取菜单列表
     * 2025/7/10
     * @return ResponseInterface
     * @throws \Exception
     */
    public function menus()
    {
        try {
            $admin = $this->request->getAttribute('admin',[]);
            $result = $this->menusLogic->menus($admin);
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Notes:获取菜单列表（树状）
     * 2025/7/15
     * @return ResponseInterface
     * @throws \Exception
     */
    public function tree()
    {
        try {
            $result = $this->menusLogic->tree();
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:获取某一个菜单的详情
     * User: Kong
     * Date: 2025/9/25
     * Time: 14:27
     * @return ResponseInterface
     * @throws \Exception
     */
    public function info()
    {
        try {
            $result = $this->menusLogic->info($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:获取菜单以及子菜单
     * User: Kong
     * Date: 2025/9/25
     * Time: 14:44
     * @return ResponseInterface
     * @throws \Exception
     */
    public function menuAndChildren()
    {
        try {
            $result = $this->menusLogic->menuAndChildren($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:创建菜单
     * User: Kong
     * Date: 2025/9/25
     * Time: 14:42
     * @return ResponseInterface
     * @throws \Exception
     */
    public function create()
    {
        try {
            $result = $this->menusLogic->create($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:更新菜单
     * User: Kong
     * Date: 2025/9/25
     * Time: 14:42
     * @return ResponseInterface
     * @throws \Exception
     */
    public function update()
    {
        try {
            $result = $this->menusLogic->update($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:删除菜单
     * User: Kong
     * Date: 2025/9/25
     * Time: 14:43
     * @return ResponseInterface
     * @throws \Exception
     */
    public function destroy()
    {
        try {
            $result = $this->menusLogic->destroy($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }
}